package com.manager.car.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.manager.car.po.AutoPartsInfo;


public class APIDaoImpl extends BaseDao<AutoPartsInfo> implements APIDao {

	//根据id查询
	public AutoPartsInfo get(Integer id) {
		return this.getHibernateTemplate().get(AutoPartsInfo.class, id);
	}
	//查询全部（首页前十条和产品分页）
	public List<AutoPartsInfo> queryAll(int ye,int size) {
		Session session=this.getFactory().openSession();
		return session.createQuery("from AutoPartsInfo order by autoId desc",AutoPartsInfo.class)
				.setFirstResult((ye-1)*size)
				.setMaxResults(size)
				.getResultList();
	}
	//查询全部产品总条数
	public Long queryAllRow() {
		return ((Long)getHibernateTemplate().find("select count(*) from AutoPartsInfo").listIterator().next());
	}
	//查询分类产品总条数
	public Long queryProRow(String pro) {
		return ((Long)getHibernateTemplate().find("select count(*) from AutoPartsInfo where autoPro='"+pro+"'").listIterator().next());
	}
	//分页查询分类产品
	public List<AutoPartsInfo> queryPro(int ye,int size,String pro) {
		Session session=this.getFactory().openSession();
		return session.createQuery("from AutoPartsInfo where autoPro='"+pro+"' order by autoId desc",AutoPartsInfo.class)
				.setFirstResult((ye-1)*size)
				.setMaxResults(size)
				.getResultList();
	}
	
	

	
	
	


	
}
